/*
 *  DIDPosition.cpp
 *  libavid
 *
 *  Created by Peter on 26.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "DIDPosition.h"
#include "AStream.h"

A_IMPLEMENT_CLASS( 'ORIG', AOrigMobRef, AObject );
A_IMPLEMENT_CLASS( 'ABOB', AMSBob, AOrigMobRef );
A_IMPLEMENT_CLASS( 'DIDP', DIDPosition, AMSBob );

void AOrigMobRef::readFromStream( AStream& str, const AObjDoc& objd )
{
	UInt8 tagMark, version;
	str.readPod( tagMark );
	str.readPod( version );
	
	str.readPod( _mobIdHigh );
	str.readPod( _mobIdLow );
	
	readMobIdFromAObjDocStream( str, _mobId );
}

#define TRACE_FIELD( x ) "\t" #x ": " << x << std::endl

void AOrigMobRef::dump( std::ostream& str ) const
{
	str << "AOrigMobRef {" << std::endl;
	
	str << TRACE_FIELD( _mobIdHigh );
	str << TRACE_FIELD( _mobIdLow );
	str << TRACE_FIELD( _mobId );
	
	str << "}" << std::endl;
}

void AMSBob::readFromStream( AStream& str, const AObjDoc& objd )
{
	AOrigMobRef::readFromStream( str, objd );
	
	UInt8 tagMark, version;
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x02 );
	TR_ASSERT( version == 0x01 );
	
	str.readPod( _sampleNum );
	str.readPod( _length );   
	str.readPod( _trkType );  
	str.readPod( _trkNum );   
}

void AMSBob::dump( std::ostream& str ) const
{
	str << "AMSBob {" << std::endl;
	
	str << "\t";
	AOrigMobRef::dump( str );
	
	str << TRACE_FIELD( _sampleNum );
	str << TRACE_FIELD( _length );
	str << TRACE_FIELD( _trkType );
	str << TRACE_FIELD( _trkNum );
	
	str << "}" << std::endl;
}

void DIDPosition::readFromStream( AStream& str, const AObjDoc& objd )
{
	AMSBob::readFromStream( str, objd );
	
	UInt8 tagMark, version;
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x02 );
	TR_ASSERT( version == 0x01 );
	
	str.readPod( _strip );     
	str.readPod( _offset );    
	str.readPod( _byteLength );
	_sPosInvalid = str.readBool();
	
	str.readPod( tagMark );
	TR_ASSERT( tagMark == 0x03 );
}

void DIDPosition::dump( std::ostream& str ) const
{
	str << "DIDPosition {" << std::endl;
	
	str << "\t";
	AMSBob::dump( str );
	
	str << TRACE_FIELD( _strip );
	str << TRACE_FIELD( _offset );
	str << TRACE_FIELD( _byteLength );
	str << TRACE_FIELD( _sPosInvalid );
	
	str << "}" << std::endl;
}